package com.jhte.scheduleJob.job;

import com.jhte.scheduleJob.entity.ScheduleJob;
import com.jhte.scheduleJob.util.TaskUtils;
import net.sf.json.JSONObject;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author
 * @Description: 若一个方法一次执行不完下次轮转时则等待改方法执行完后才执行下一次操作
 * @date
 */
@DisallowConcurrentExecution
public class ConcurrentQuartzJobFactory implements Job {

    public final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        String jobJson = context.getMergedJobDataMap().getString("scheduleJob");
        JSONObject jsonObject = JSONObject.fromObject(jobJson);
        ScheduleJob scheduleJob = (ScheduleJob) JSONObject.toBean(jsonObject, ScheduleJob.class);
        //ScheduleJob scheduleJob = (ScheduleJob) context.getMergedJobDataMap().get("scheduleJob");
        TaskUtils.invokMethod(scheduleJob);

    }
}